package com.leetcode.August;

import java.util.HashSet;
import java.util.List;

/**
 * @Description: 139. 单词拆分
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-09 17:19
 */
public class LC139单词拆分 {
    public boolean wordBreak(String s, List<String> wordDict) {
        HashSet<String> set = new HashSet<>(wordDict);
        boolean[] dp = new boolean[s.length() + 1];
        dp[0] = true;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < i; j++) {
                if (set.contains(s.substring(j, i)) && dp[j]){
                    dp[i] = true;
                }
            }
        }
        return dp[s.length()];
    }
}
